package com.ruihang.generalibrary.ui.dialog;

import android.app.Dialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.ruihang.generalibrary.R;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;

/**
 * 系统分享对话框
 * Created by raoweiwei on 2017/8/7.
 */

public class SystemShareDialogFragment extends BaseDialogFragment {
    private CustomFontTextView mTvTitle;
    private CustomFontTextView mBtnTextSharing;
    private CustomFontTextView mBtnPicSharing;
    private CustomFontTextView mBtnPicsSharing;
    private View mDvTextSharing;
    private View mDvPicSharing;
    private View mDvPicsSharing;

    private OnViewClick onViewClick;
    private int mType = SHARE_TYPE_ALL;
    private String mTitleStr;

    public static final int SHARE_TYPE_TEXT = 0;
    public static final int SHARE_TYPE_TEXT_AND_PIC = 1;
    public static final int SHARE_TYPE_TEXT_AND_PICS = 2;
    public static final int SHARE_TYPE_PIC = 3;
    public static final int SHARE_TYPE_PICS = 4;
    public static final int SHARE_TYPE_ALL = 5;

    public static final int VIEW_ITEM_TEXT = 0;
    public static final int VIEW_ITEM_PIC = 1;
    public static final int VIEW_ITEM_PICS = 2;

    @Override
    protected int getContentRes() {
        return R.layout.fragment_system_share_dialog;
    }

    @Override
    protected void initViews(Dialog dialog, Bundle savedInstanceState) {
        mTvTitle = (CustomFontTextView) dialog.findViewById(R.id.system_share_tv_title);
        mBtnTextSharing = (CustomFontTextView) dialog.findViewById(R.id.system_share_btn_text_sharing);
        mBtnPicSharing = (CustomFontTextView) dialog.findViewById(R.id.system_share_btn_pic_sharing);
        mBtnPicsSharing = (CustomFontTextView) dialog.findViewById(R.id.system_share_btn_pics_sharing);
        mDvTextSharing = dialog.findViewById(R.id.system_share_dv_text_sharing);
        mDvPicSharing = dialog.findViewById(R.id.system_share_dv_pic_sharing);
        mDvPicsSharing = dialog.findViewById(R.id.system_share_dv_pics_sharing);
        mBtnTextSharing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onViewClick == null || onViewClick.onViewClick(view, VIEW_ITEM_TEXT, 0)) {
                    dismiss();
                }
            }
        });
        mBtnPicSharing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onViewClick == null || onViewClick.onViewClick(view, VIEW_ITEM_PIC, 0)) {
                    dismiss();
                }
            }
        });
        mBtnPicsSharing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onViewClick == null || onViewClick.onViewClick(view, VIEW_ITEM_PICS, 0)) {
                    dismiss();
                }
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        if (TextUtils.isEmpty(mTitleStr)) {
            mTvTitle.setVisibility(View.GONE);
        } else {
            mTvTitle.setVisibility(View.VISIBLE);
            mTvTitle.setText(mTitleStr);
        }
        switch (mType) {
            case SHARE_TYPE_TEXT:
                mBtnPicSharing.setVisibility(View.GONE);
                mDvPicSharing.setVisibility(View.GONE);
                mBtnPicsSharing.setVisibility(View.GONE);
                mDvPicsSharing.setVisibility(View.GONE);
                break;
            case SHARE_TYPE_TEXT_AND_PIC:
                mBtnPicsSharing.setVisibility(View.GONE);
                mDvPicsSharing.setVisibility(View.GONE);
                break;
            case SHARE_TYPE_TEXT_AND_PICS:
                mBtnPicSharing.setVisibility(View.GONE);
                mDvPicSharing.setVisibility(View.GONE);
                break;
            case SHARE_TYPE_PIC:
                mBtnTextSharing.setVisibility(View.GONE);
                mDvTextSharing.setVisibility(View.GONE);
                mBtnPicsSharing.setVisibility(View.GONE);
                mDvPicsSharing.setVisibility(View.GONE);
                break;
            case SHARE_TYPE_PICS:
                mBtnTextSharing.setVisibility(View.GONE);
                mDvTextSharing.setVisibility(View.GONE);
                mBtnPicSharing.setVisibility(View.GONE);
                mDvPicSharing.setVisibility(View.GONE);
                break;
            default:
            case SHARE_TYPE_ALL:

                break;
        }
    }

    public SystemShareDialogFragment setShareType(int type) {
        mType = type;
        return this;
    }

    public SystemShareDialogFragment setTitleStr(String str) {
        mTitleStr = str;
        return this;
    }

    public SystemShareDialogFragment setOnViewClick(OnViewClick onViewClick) {
        this.onViewClick = onViewClick;
        return this;
    }

    public interface OnViewClick {
        /**
         * @param view
         * @param viewItem
         * @param mode
         * @return 是否dismiss
         */
        boolean onViewClick(View view, int viewItem, int mode);
    }
}
